import java.util.Scanner;

public class NK_HJ71 {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String str1 = s.nextLine();
        String str2 = s.nextLine();
        System.out.print(macth(str1,str2));
    }
    public static boolean macth(String str1,String str2) {
        char[] c1 = str1.toCharArray();
        char[] c2 = str2.toCharArray();
        int len1 = c1.length;
        int len2 = c2.length;
        boolean[][] dp = new boolean[len1 + 1][len2 + 1];
        dp[0][0] = true;
        for(int i = 1; i <= len1; i++) {
            for(int j = 0; j <= len2; j++) {
                if(c1[i - 1] == '*') {
                    if(j != 0) {
                        if(c2[j - 1] == '.' || (c2[j - 1] >= '0' && c2[j - 1] <= '9')
                                || (c2[j - 1] >= 'a' && c2[j - 1] <= 'z') || c2[j - 1] >= 'A'
                                && c2[j - 1] <= 'Z') {
                            dp[i][j] = dp[i - 1][j] || dp[i][j - 1];
                        }
                    }else {
                        dp[i][j] = dp[i - 1][j];
                    }
                }else {
                    if(j > 0 && defs(c1[i - 1],c2[j - 1])) {
                        dp[i][j] = dp[i - 1][j - 1];
                    }
                }
            }
        }
        return dp[len1][len2];
    }
    public static boolean defs(char c1,char c2) {
        if(c1 == '?') return true;
        if(c1 >= 'a' && c1 <= 'z') {
            c1 = (char)(c1 - 'a' + 'A');
        }
        if(c2 >= 'a' && c2 <= 'z') {
            c2 = (char)(c2 - 'a' + 'A');
        }
        return c1 == c2;
    }
}
